package module

import (
	"context"
	"fmt"

	"gitee.com/mkwchecking/sr-core/config/source"
	"gitee.com/mkwchecking/sr-core/domain"
	"gitee.com/mkwchecking/sr-core/storage/database"
)

var _ domain.IDomain = (*TestModule)(nil)

func NewTestModule() domain.IDomain {
	return &TestModule{}
}

type TestModule struct {
}

// Install implements domain.IDomain.
func (t *TestModule) Install(ctx context.Context) error {
	fmt.Println("module test install ...")
	_, ok := database.FromCtx(ctx)
	if !ok {
		return fmt.Errorf("database not found")
	}

	return nil
}

// BeforeStart implements domain.IDomain.
func (t *TestModule) BeforeStart(src source.ISource) error {
	return nil
}

// Start implements domain.IDomain.
func (t *TestModule) Start(ctx context.Context) error {
	fmt.Println("module test start ...")
	return nil
}

// Stop implements domain.IDomain.
func (t *TestModule) Stop(ctx context.Context) error {
	fmt.Println("module test stop ...")
	return nil
}
